/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.edu.unju.fi.reservahabitaciones.grupo14.struts.modelo.dao.impl;

import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.modelo.dao.RolDao;
import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.hibernate.HibernateUtil;
import java.util.List;
import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.modelo.dominio.Rol;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
/**
 *
 * @author mauriljb
 */
public class RolDaoImpl implements RolDao {
    
    @Override
     public List<Rol> getAll() {
            Session session = ar.edu.unju.fi.reservahabitaciones.grupo14.struts.hibernate.HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            Criteria criteria = session.createCriteria(Rol.class);
            criteria.addOrder(Order.asc("rolId"));
            List<Rol> lista = criteria.list();
            session.close();
            return lista;
    }
     
    @Override
      public Rol getRol(long id) {
       Session session = HibernateUtil.getSessionFactory().openSession();
       session.beginTransaction();
       Criteria criteria = session.createCriteria(Rol.class);
       criteria.add(Restrictions.eq("id", id));
       Rol Rol = (Rol) criteria.list().get(0);
       session.close();
       return Rol;
    }
      
    @Override
       public void insert(Rol rol) {
          Session session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            session.save(rol);
            session.getTransaction().commit();
            session.close();
    }
       
    @Override
        public void delete(Rol rol) {
          Session session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            session.delete(rol);
            session.getTransaction().commit();
            session.close();
    }
    @Override
         public void update(Rol rol) {
          Session session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            session.update(rol);
            session.getTransaction().commit();
            session.close();
    }
    
}
